/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package gui;

import action.AddAction;
import action.ClearAction;
import action.ConnectAction;
import action.DeleteAction;
import action.DetachAction;
import diagram.handles.Handle;
import diagram.locations.AbsoluteLocation;
import diagram.locations.Location;
import javax.swing.JMenuItem;
import model.DiagramModel;

/**
 *
 * @author Jelle
 */
public class DiagramPopup extends Popup {
    private JMenuItem m;
    private DiagramModel model;

    public DiagramPopup(DiagramModel model) {
        this.model = model;
    }

    public void clearMenu() {
        getPopup().removeAll();
    }

    public void menuPanel(AbsoluteLocation location) {
        clearMenu();
        m = new JMenuItem(new ClearAction(model));
        m.setText("Clear All");
        getPopup().add(m);
        m = new JMenuItem("Attach");
        getPopup().add(m);
        m = new JMenuItem("Clear Selection");
        getPopup().add(m);
        getPopup().addSeparator();
        m = new JMenuItem(new AddAction("normal", location, model));
        m.setText("Add simple Node");
        getPopup().add(m);
    }

    public void menuNode() {
        clearMenu();
        m = new JMenuItem(new AddAction("inputhandle", null, model));
        m.setText("Add Inputhandle");
        getPopup().add(m);
        m = new JMenuItem(new AddAction("outputhandle", null, model));
        m.setText("Add Outputhandle");
        getPopup().add(m);
        m = new JMenuItem(new AddAction("connect", null, model));
        m.setText("Add Connecthandle");
        getPopup().add(m);
        m = new JMenuItem(new AddAction("triggerhandle", null, model));
        m.setText("Add Triggerhandle");
        getPopup().add(m);
        getPopup().addSeparator();
        m = new JMenuItem(new DeleteAction("all", model));
        m.setText("delete Node (all)");
        getPopup().add(m);
        m = new JMenuItem(new DeleteAction("normal", model));
        m.setText("delete Node (normal)");
        getPopup().add(m);
        getPopup().addSeparator();
        m = new JMenuItem("Properties");
        super.getPopup().add(m);
    }

    public void menuHandle(AbsoluteLocation location, Handle h) {
        clearMenu();
        m = new JMenuItem(new DetachAction(h, model));
        m.setText("Detach Handle");
        getPopup().add(m);
        getPopup().addSeparator();
        m = new JMenuItem(new DeleteAction("all", model));
        m.setText("Delete Handle");
        getPopup().add(m);
        m = new JMenuItem("Properties");
        getPopup().add(m);
    }

    public void menuPort(AbsoluteLocation location, Handle h) {
        clearMenu();
        m = new JMenuItem(new AddAction("triggerhandle", null, model));
        m.setText("Add Triggerhandle");
        getPopup().add(m);
       
        getPopup().addSeparator();
        m = new JMenuItem(new DeleteAction("all", model));
        m.setText("Delete Handle");
        getPopup().add(m);
        m = new JMenuItem("Properties");
        getPopup().add(m);
    }

    public void menuAttach(Handle h, Location target) {
        clearMenu();
        m = new JMenuItem(new ConnectAction("trigger", h, target, model));
        m.setText("attach");
        getPopup().add(m);

    }

    public void menuConnection() {
        clearMenu();
        m = new JMenuItem(new DeleteAction("Connection", model));
        m.setText("Delete Connection");
        getPopup().add(m);

        getPopup().addSeparator();
        m = new JMenuItem("Properties");
        getPopup().add(m);
    }
}
